local skel = fk.CreateSkill {
  name = "lb__jianyuan",
}

Fk:loadTranslationTable {
  ["lb__jianyuan"] = "茧源",
  [":lb__jianyuan"] = "每回合限一次，其他角色对你造成伤害后，你可弃置一张牌并令其选择一项：1.你回复1点体力；2.弃置一张牌并横置；若你的体力值不为全场最少，你摸两张牌。",

  ["#lb__jianyuan"] = "茧源：你可以弃置一张牌令%dest选择弃牌并横置或令你回复1点体力",
  ["#lb__jianyuan-dis"] = "茧源：你可以弃置一张牌，或取消后%dest回复1点体力",

  ["$lb__jianyuan1"] = "我会继续战斗。",
  ["$lb__jianyuan2"] = "我为自我而战。",
}

skel:addEffect(fk.Damage, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target and target ~= player and not target.dead and data.to == player
        and player:usedSkillTimes(skel.name) == 0 and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      skill_name = skel.name,
      cancelable = true,
      prompt = "#lb__jianyuan::" .. target.id,
      skip = true,
    })
    event:setCostData(self, { cards = cards })
    return #cards > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self).cards, skel.name, player, player)
    if #room:askToDiscard(target, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = skel.name,
          cancelable = true,
          prompt = "#lb__jianyuan-dis::" .. player.id,
        }) > 0 then
      if not target.chained then
        target:setChainState(true)
      end
    else
      room:recover {
        who = player,
        num = 1,
        recoverBy = player,
        skillName = skel.name
      }
    end
    if table.find(room:getOtherPlayers(player), function(p)
          return p.hp >= player.hp
        end) then
      player:drawCards(2, skel.name)
    end
  end,
})

return skel
